################################
# PLOT LA RÉSISTANCE FIGHTERS #
################################
# Author: Kasia Nalewajko
# First created: 12 March 2022
# Replicated: 8 June 2024

rm(list = ls())

# LOAD PACKAGES -----------------------------------------------------------

if (!require("dplyr")) install.packages("dplyr")
if (!require("viridis")) install.packages("viridis")
if (!require("ggplot2")) install.packages("ggplot2")
if (!require("sf")) install.packages("sf")

# LOAD DATA ---------------------------------------------------------------

load("./00 SUBMITTED/00 APSR final/04 replication_files/01 data/main.Rda")
frcantons1940 <- sf::read_sf("./data/other/maps/france1940/CANTONS_1940/CANTONS_1940.shp")

# CLEAN AND PLOT ----------------------------------------------------------

france1940_sf <- st_as_sf(frcantons1940)

ressum <- main %>% 
  group_by(deppct) %>% 
  mutate(nresisters = FFIFFCgentile*1000/pop1936) 

france1940_sf <- left_join(france1940_sf, ressum)

france1940_sf %>%
  ggplot() +
  geom_sf() +
  aes(fill = log(nresisters+1)) +
  scale_fill_viridis(
    option = "inferno",
    trans = "reverse",
    na.value="gray90"
  ) +
  theme_bw() +
  theme(axis.text.x=element_blank(),
        axis.text.y=element_blank(),
        legend.position="bottom") +
  labs(title = "",
       subtitle = "",
       fill = "Number FFI and FFC insurgents per 1,000 inhabitants (logged)",
       x = "",
       y = "")

# SAVE ----------------------------------------------------------

ggsave(
  "A2_resisters_cantons_map.png",
  plot = last_plot(),
  path = "./00 SUBMITTED/00 APSR final/02 supplementary_materials/maps",
  width = 15,
  height = 15,
  units = "cm",
  dpi = 300
)

